package org.molamil.acto.types {
	import org.molamil.acto.core.parsers.ParserError;	
	
	import flexunit.framework.TestCase;	
	
	/**
	 * @author Jorge Hernandez
	 */
	public class UintTypeParserTest extends TestCase {
		
		
		// PROPERTIES
		
		private var instance:UintTypeParser;
		
		
		// CONSTRUCTOR
		
		public function UintTypeParserTest(methodName:String = null) {
			super(methodName);
		}
		
		
		// PUBLIC METHODS
		
		override public function setUp():void {
			instance = new UintTypeParser();
		}
		
		override public function tearDown():void {
			instance = null;
		}
		
		public function testParse():void {
			
			assertEquals("'100' parses to 100", 100, instance.parse("100"));
			assertEquals("'028' parses to 28", 28, instance.parse("28"));
			assertEquals("'0x100' parses to 256", 256, instance.parse("0x100"));
			assertEquals("'0xFF0000' parses to 16711680", 16711680, 
				instance.parse("0xFF0000"));
			assertEquals("'126e3' parses to 126000", 126000, instance.parse("126e3"));
			
			try {
				instance.parse("-10");
				fail("'-10' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("-0x100");
				fail("'-0x100' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("Infinity");
				fail("'Infinity' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("126e-3");
				fail("'126e-3' should fail (decimal)");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("32000000000000000000");
				fail("'32000000000000000000' should fail (too big)");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("-32000000000000000000");
				fail("'-32000000000000000000' should fail (too small)");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("-25.75");
				fail("'-25.75' should fail (decimal)");
			} catch (e:ParserError) {}
			
			try {
				instance.parse(".5");
				fail("'.5' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1 00");
				fail("'1 00' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("a100");
				fail("'a100' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("xFF0000");
				fail("'xFF0000' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("5,5");
				fail("'5,5' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("100f");
				fail("'100f' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("..5");
				fail("'..5' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("5.5.5");
				fail("'5.5.5' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("0x5.5");
				fail("'0x5.5' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("");
				fail("'' (empty string) should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse(null);
				fail("null should fail");
			} catch (e:ParserError) {}
			
			
		}
		
		
	}
	
}
